var submitBtn = document.getElementById("submit");
var namevalue = document.querySelector('#namevalue')
var passwordvalue = document.querySelector('#passwordvalue')
var user = {}
submitBtn.onclick = function (event) {
    var name = namevalue.value.trim()
    var password = passwordvalue.value.trim()
    if (name.length == 0) {
        alert('请输入用户名')
        return false;
    }
    else if (password.length == 0) {
        alert('请输入密码')
        return false;
    }

    ajax({
        type: 'post',
        url: '/admin/login',
        data: {
            name,
            password
        },
        success: (result) => {
            alert('登陆成功')
            // 存储 用户的名称到本地
            window.location.href = "index.html"
            localStorage.setItem("uname", result.name);
            localStorage.setItem("id", result.id);
            return false;
        },
        error: (result) => {
            alert('账号或者密码错误')
        }
    })
    return false;
};